﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Dome.Card.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class first : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "owners",
                columns: table => new
                {
                    id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    name = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    sex = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    cardNum = table.Column<int>(type: "int", nullable: false),
                    phoneNum = table.Column<int>(type: "int", nullable: false),
                    password = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    homeAddress = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    roomNum = table.Column<int>(type: "int", nullable: false),
                    isdelete = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_owners", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "parks",
                columns: table => new
                {
                    id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    img = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    type = table.Column<bool>(type: "bit", nullable: false),
                    ownerId = table.Column<int>(type: "int", nullable: false),
                    style = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_parks", x => x.id);
                    table.ForeignKey(
                        name: "FK_parks_owners_ownerId",
                        column: x => x.ownerId,
                        principalTable: "owners",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "comments",
                columns: table => new
                {
                    id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ownerId = table.Column<int>(type: "int", nullable: false),
                    parkId = table.Column<int>(type: "int", nullable: false),
                    title = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    content = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    img = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    isdelete = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_comments", x => x.id);
                    table.ForeignKey(
                        name: "FK_comments_owners_ownerId",
                        column: x => x.ownerId,
                        principalTable: "owners",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "FK_comments_parks_parkId",
                        column: x => x.parkId,
                        principalTable: "parks",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "leaseHistroys",
                columns: table => new
                {
                    id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    parkId = table.Column<int>(type: "int", nullable: false),
                    ownerId = table.Column<int>(type: "int", nullable: false),
                    leaseDay = table.Column<DateTime>(type: "datetime2", nullable: false),
                    month = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_leaseHistroys", x => x.id);
                    table.ForeignKey(
                        name: "FK_leaseHistroys_owners_ownerId",
                        column: x => x.ownerId,
                        principalTable: "owners",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "FK_leaseHistroys_parks_parkId",
                        column: x => x.parkId,
                        principalTable: "parks",
                        principalColumn: "id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_comments_ownerId",
                table: "comments",
                column: "ownerId");

            migrationBuilder.CreateIndex(
                name: "IX_comments_parkId",
                table: "comments",
                column: "parkId");

            migrationBuilder.CreateIndex(
                name: "IX_leaseHistroys_ownerId",
                table: "leaseHistroys",
                column: "ownerId");

            migrationBuilder.CreateIndex(
                name: "IX_leaseHistroys_parkId",
                table: "leaseHistroys",
                column: "parkId");

            migrationBuilder.CreateIndex(
                name: "IX_parks_ownerId",
                table: "parks",
                column: "ownerId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "comments");

            migrationBuilder.DropTable(
                name: "leaseHistroys");

            migrationBuilder.DropTable(
                name: "parks");

            migrationBuilder.DropTable(
                name: "owners");
        }
    }
}
